package 力扣.栈;

import java.util.Deque;
import java.util.LinkedList;

public class 数组左边第一个比我大的元素 {
    //左边：从左到右遍历
    public static int[] findLeftLarge(int[] A) {
        Deque<Integer> stack = new LinkedList<>();
        int[] ans = new int[A.length];
        for (int i = 0; i < A.length; i++) {
            while (!stack.isEmpty() && A[stack.peek()] <= A[i]){// ‘>=’ :比我小
                stack.poll();
            }
            if (!stack.isEmpty()){
                ans[i] = stack.peek();
            }else {
                ans[i] = -1;
            }
            stack.push(i);
        }
        return ans;
    }
}
